<template>
    <div class="ma">
        <common-header></common-header>
        <m-header></m-header>
        <main>
            <common-banner :banner="banner"></common-banner>
            <div class="con_box">
                <common-user></common-user>
                <!-- <div class="sub_btn" @click="quit">退出登录</div> -->
            </div>
        </main>
        <common-footer></common-footer>
    </div>
</template>
<script>
import CommonHeader from '@/components/commonheader'
import CommonFooter from '@/components/commonfooter'
import CommonBanner from '@/components/commonBanner'
import commonNav from '@/components/commonNav'
import commonUser from '@/components/commonUser'
import mHeader from '@/components/mobilenav'
export default {
    data(){
        return{
            banner:[],
            ismobile:false,
            wid:'',
            userinfo:null
        };
    },
    created(){
            this.wid = document.body.clientWidth
            if(this.wid<900){
            this.ismobile = true
            this.getmobile()
            }else{
                this.getdata()
                this.ismobile = false
            }
        },
    mounted(){
        let token = localStorage.getItem('token')
        if(!token){
            this.$router.push({
                path:'/prevlogin'
            })
        }else{
            this.token = token
            this.getuserInfo()
        }
    },
    watch:{
        
    },
    methods:{
        getuserInfo(){
            this.$api.get('getUserInfo',{
                headers:{
                    Authorization:localStorage.getItem('token')
                }
            }).then(res=>{
                if(res.code === 200){
                    localStorage.setItem('userInfo',JSON.stringify(res.data.data))
                    this.userinfo = res.data.data
                }else{
                    alert(res.message)
                    localStorage.removeItem('token')
                    localStorage.removeItem('userInfo')
                    this.$router.push({path:'/prevlogin'})
                }
            })
        },
        quit(){
        localStorage.removeItem('token')
        localStorage.removeItem('userInfo')
        alert('退出成功！')
        this.$router.push({
          path:'/'
        })
      },
        getdata(){
                this.$api.post('getAdList',{
                    "sort":"sort",
                    "limit":100, 
                    "group":"实绩管理" 
                },{
                    headers:{
                        Authorization:this.token
                    }
                }).then(res=>{
                    this.banner = res.data.list
                })
            },
            getmobile(){
                this.$api.post('getAdList',{
                    "sort":"sort",
                    "limit":100, 
                    "group":"实绩管理banner手机端" 
                }).then(res=>{
                    this.banner = res.data.list
                })
            },
    },
    components:{
        CommonBanner,
        CommonFooter,
        CommonHeader,
        commonNav,
        commonUser,
        mHeader
    }
}
</script>
<style lang="scss" scoped>
.con_box{
    width: 1200px;
    margin: 0 auto;
    .sub_btn{
        width: 60%;
        height: 62px;
        line-height: 62px;
        text-align: center;
        background: #e0e0e0;
        margin: 0 auto;
        font-size: 16px;
        color: #888;
    }
}
@media screen and (max-width: 900px) {
    .con_box{
        width: 100%;
        margin: 0 auto;
        padding: 0 .3rem;
        box-sizing: border-box;
    }
    .ma{
        padding-bottom: 1.2rem;
    }
}

</style>